package com.ly.blog2Admin.controller;


import com.alibaba.fastjson.JSONObject;
import com.ly.blog2Admin.dao.model.SysConfig;
import com.ly.blog2Admin.service.SysConfigService;
import com.ly.blog2Common.core.http.ResponseMessage;
import com.ly.blog2Common.core.page.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统配置控制器
 * @author Louis
 * @date Jan 13, 2019
 */
@RestController
@RequestMapping("config")
public class SysConfigController {

	@Autowired
	private SysConfigService sysConfigService;
	
	@PreAuthorize("hasAuthority('sys:config:add') AND hasAuthority('sys:config:edit')")
	@PostMapping(value="/save")
	public JSONObject save(@RequestBody SysConfig record) {
		return ResponseMessage.ok(sysConfigService.save(record));
	}

	@PreAuthorize("hasAuthority('sys:config:delete')")
	@PostMapping(value="/delete")
	public JSONObject delete(@RequestBody List<SysConfig> records) {
		return ResponseMessage.ok(sysConfigService.delete(records));
	}

	@PreAuthorize("hasAuthority('sys:config:view')")
	@PostMapping(value="/findPage")
	public JSONObject findPage(@RequestBody PageRequest pageRequest) {
		return ResponseMessage.ok(sysConfigService.findPage(pageRequest));
	}
	
	@PreAuthorize("hasAuthority('sys:config:view')")
	@GetMapping(value="/findByLable")
	public JSONObject findByLable(@RequestParam String lable) {
		return ResponseMessage.ok(sysConfigService.findByLable(lable));
	}
}
